import { stringify } from 'qs';
import request from '@/utils/request';

export default {
  namespace: 'role',

  state: {
    queryForm: {},

    table: {
      dataSource: [],
      pagination: {
        pageSize: 10,
        current: 1,
        total: 0,
      },
    },
  },

  effects: {
    *fetch({ payload }, { call, put }) {
      const queryRole = async function queryRule(params) {
        return request(`/api/sys/menu/query?${stringify(params)}`);
      };
      const response = yield call(queryRole, payload);
      yield put({
        type: 'save',
        payload: response,
      });
    },
  },

  reducers: {
    save(state, action) {
      return {...state, ...action.payload};
    },
  },
};
